<?php
/**	
* Controller
* DashBoard
* @author Filipe Dutra
* Created on 22/08/2012
* @version 1.0
* @copyright GETESB - Grupo Águas do Brasil                                        
*/
class Dashboard
	extends Smvc {	

	
	public function __construct(){
		
			parent::__construct();
			 if(!isset($_SESSION['login'])){$this->jump();}
			$this->nucleo=new nucleo;					
			$this->gproj=new gproj;
	}


	public function index(){ 
	
			$q = Smvc::this()->sql->query('SELECT COUNT(PRO_STATUS)VAL, PRO_STATUS ITEM FROM PROJETO GROUP BY PRO_STATUS ORDER BY VAL');
			if($q){
				$data['graf']['1']['titulo'] = 'Status Global dos Projetos - 2012';
				foreach($q as $v){
					$data['graf']['1']['itens'][$v->ITEM] = $v->VAL;
				}				
			}
			
			// -----------------------------------------------------------------------------------------------------------			
			$q2 = Smvc::this()->sql->query('SELECT COUNT(PRO_COD_AREA)VAL, ARE_NOME ITEM
												FROM PROJETO,AREA 
												WHERE PRO_COD_AREA = ARE_CODIGO
												GROUP BY PRO_COD_AREA, ARE_NOME 
												ORDER BY VAL');
			if($q2){
				$data['graf']['2']['titulo'] = 'Projetos por Área - 2012';
				foreach($q2 as $v){
					$data['graf']['2']['itens'][] = $v->VAL;
					$data['graf']['2']['cat'][] = $v->ITEM;
				}				
			}
			
			// -----------------------------------------------------------------------------------------------------------
			$q3 = Smvc::this()->sql->query('SELECT ARE_NOME ITEM, COUNT(PRO_COD_AREA)VAL
											FROM PROJETO,AREA 
											WHERE PRO_COD_AREA = ARE_CODIGO
											GROUP BY ARE_NOME, PRO_COD_AREA
											ORDER BY ITEM');
			if($q3){
				$data['graf']['3']['titulo'] = 'Projetos por Área - 2012';
				foreach($q3 as $v){
					$data['graf']['3']['itens'][] = $v->VAL;
					$data['graf']['3']['cat'][] = $v->ITEM;
				}
			}
			
			// -----------------------------------------------------------------------------------------------------------
			$data['titulo'] = 'Dashboard';			
			//exit('<pre>'.print_r($data, true).'</pre>');
			
			// -----------------------------------------------------------------------------------------------------------
			//$data['js']="dashboard";			
			$this->view('dashboard',$data,'site');	
	}
	
}